import { Component, OnInit } from '@angular/core';
import { Singlepage } from '../../model/singlepage';
import { SinglepageService } from '../../service/singlepage.service';
import { Router, ActivatedRoute } from '@angular/router';

@Component({
  selector: 'app-singlepagedetail',
  templateUrl: './singlepagedetail.component.html',
  styleUrls: ['./singlepagedetail.component.css']
})
export class SinglepagedetailComponent implements OnInit {
  sl:Array<Singlepage>;
  singlepage:Singlepage;
  parm:string;

  constructor(
    private singlepageservice:SinglepageService,
    private router:Router,
    private routerinfo:ActivatedRoute
  ) {this.sl=new Array();
    this.singlepage=new Singlepage();
   }

  ngOnInit() {
    this.parm=this.routerinfo.snapshot.params["id"];
    if(this.parm){
      this.getSinglesinglepage(this.parm);
    }
    else{
      alert("参数异常，请重试");
      this.goBack();
    }
  }

  getSinglesinglepage(id:string){
    this.singlepageservice.getSinglepage(id)
    .then((data:Singlepage)=>{
      if(data){
        this.singlepage=data;
      }
      else{
        alert("通讯异常，请刷新后重试")
      }
    })
  }

  goBack(){

    this.router.navigate(['index']);

  }

}
